<?php

/**
 * 螺丝帽发送短信
 * @param $tel
 * @param $content
 * @return mixed
 */
function mms($tel,$content){
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "http://sms-api.luosimao.com/v1/send.json");

    curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 30);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
    curl_setopt($ch, CURLOPT_HEADER, FALSE);

    curl_setopt($ch, CURLOPT_HTTPAUTH , CURLAUTH_BASIC);
    curl_setopt($ch, CURLOPT_USERPWD  , 'api:key-'.config("constants.luosimaoKey"));

    curl_setopt($ch, CURLOPT_POST, TRUE);
    curl_setopt($ch, CURLOPT_POSTFIELDS, array('mobile' => $tel,'message' => $content.config("constants.luosimaoSign")));

    $res = curl_exec( $ch );
    curl_close( $ch );
    return $res;
}

/**
 * 发短信验证码
 * @param $mobile
 * @param $code
 * @return mixed
 */
function sendMobileCode($mobile, $code) {

    $content = "验证码为：".$code."请在5分钟之内输入";

    return mms($mobile, $content);

}